package com.woniu.apartment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.woniu.apartment.domain.ExchangeRate;
import com.woniu.apartment.service.IExchangeRateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 汇率Controller
 * 
 * @author yy
 * @date 2023-04-03
 */
@RestController
@RequestMapping("/apartment/tbexchangerate")
@Api("汇率管理")
public class ExchangeRateController extends BaseController
{
    @Autowired
    private IExchangeRateService exchangeRateService;

    /**
     * 查询汇率列表
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbexchangerate:list')")
    @GetMapping("/list")
    @ApiOperation("汇率分页查询")
    public TableDataInfo list(ExchangeRate exchangeRate)
    {
        startPage();
        List<ExchangeRate> list = exchangeRateService.selectExchangeRateList(exchangeRate);
        return getDataTable(list);
    }

    /**
     * 导出汇率列表
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbexchangerate:export')")
    @Log(title = "汇率", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("汇率导出")
    public void export(HttpServletResponse response, ExchangeRate exchangeRate)
    {
        List<ExchangeRate> list = exchangeRateService.selectExchangeRateList(exchangeRate);
        ExcelUtil<ExchangeRate> util = new ExcelUtil<ExchangeRate>(ExchangeRate.class);
        util.exportExcel(response, list, "汇率数据");
    }

    /**
     * 获取汇率详细信息
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbexchangerate:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("根据主键查询汇率")
    @ApiImplicitParam(name = "ids", value = "用户ID", required = true, dataType = "Long")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(exchangeRateService.selectExchangeRateById(id));
    }

    /**
     * 新增汇率
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbexchangerate:add')")
    @Log(title = "汇率", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("添加汇率")
    public AjaxResult add(@RequestBody ExchangeRate exchangeRate)
    {
        return toAjax(exchangeRateService.insertExchangeRate(exchangeRate));
    }

    /**
     * 修改汇率
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbexchangerate:edit')")
    @Log(title = "汇率", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("更新汇率")
    public AjaxResult edit(@RequestBody ExchangeRate exchangeRate)
    {
        return toAjax(exchangeRateService.updateExchangeRate(exchangeRate));
    }

    /**
     * 删除汇率
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbexchangerate:remove')")
    @Log(title = "汇率", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除汇率")
    @ApiImplicitParam(name = "ids", value = "主键数组", required = true, dataType = "Long")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(exchangeRateService.deleteExchangeRateByIds(ids));
    }
}
